package com.itheima.service.impl;

import com.itheima.dao.AccountDao;
import com.itheima.domain.Account;
import com.itheima.service.AccountService;
import com.itheima.transaction.MyTransaction;
import com.itheima.transaction.TransactionManager;
import com.itheima.utils.DataSourceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.management.RuntimeErrorException;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * 业务层意思
 *
 */
@Service("accountService")
public class AccountServiceImpl implements AccountService {
    @Autowired
    private AccountDao accountDao;



    @Override
    @SuppressWarnings("all")
    @MyTransaction(true)
    public void transfer(int from, int to, double money) {

        accountDao.add(to,money);
        int i=5/0;
        accountDao.sub(from,money);
        //调用别人写的方法


    }


    @Override
    @MyTransaction
    public void delete(int id) {
        accountDao.delete(id);
    }

    @Override
    @MyTransaction
    public void add(Account account) {

        accountDao.save(account);

    }

    @Override
    @MyTransaction
    public Account findById(int id) {


        return accountDao.findById(id);
    }

    public void  xxx(){
        System.out.println("我是该类中一个辅助方法~~~~");
    }
}
